package com.example.result.explore

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue

var i = 0

@Composable
fun EffectsExpose() {
    Column {
        i++
        var state by remember {
            i = 0
            mutableStateOf(false)
        }
        if (state) {
            Text(text = "因为这里读取了state，所以导致组件重组")
        }
        Text(text = "Composable:如果'触发状态改变'使得i值改变，则说明组合函数进行了重组：$i")
        Button(onClick = { state = !state }) {
            Text(text = "触发状态改变:$state")
        }
        var updateI by remember {
            mutableStateOf(i)
        }
        Text(text = "SideEffect:该值在重组完成后更新:$updateI ")
        SideEffect {
            if (state) {
                updateI = i
            }
        }
    }

}